#!/bin/bash
NDK_HOME=/Users/sym/Library/Android/sdk/ndk/22.0.7026061
HOST_TAG=darwin-x86_64
PLATFORM=$NDK_HOME/platforms/android-21/arch-arm64/
TOOLCHAIN=$NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG
ANDROID_BIN=$NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG/bin

API=21

CPU=aarch64

CROSS_COMPILE=${ANDROID_BIN}/${CPU}-linux-android

CC_CROSS_COMPILE=${ANDROID_BIN}/${CPU}-linux-android

PREFIX=./android/${CPU}


export CXX="${CC_CROSS_COMPILE}${API}-clang++"

export CC="${CC_CROSS_COMPILE}${API}-clang"

export AR="${CROSS_COMPILE}-ar"

export LD="${CROSS_COMPILE}-ld"

export AS="${CROSS_COMPILE}-as"

export STRINGS="${CROSS_COMPILE}-strings"

export STRIP="${CROSS_COMPILE}-strip"

export RANLIB="${CROSS_COMPILE}-ranlib"

export INSTALL="/usr/bin/install"


echo "==============="
echo ${CC}
echo "==============="

./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-pic \
--enable-strip \
--sysroot=$TOOLCHAIN/sysroot/ \
--host=aarch64-linux \
--disable-asm \
--extra-cflags="-Os -fpic" \
--extra-ldflags=""

make clean
make -j4
make install